//
//  FirstViewController.m
//  TabNav
//
//  Created by Kalyan Mudumbai on 8/28/10.
//  Copyright GOLDMAN SACHS 2010. All rights reserved.
//

#import "FirstViewController.h"
#import "InfoViewController.h"
#import "PerumalViewController.h"


@implementation FirstViewController
@synthesize ivController;
@synthesize pvController;

-(IBAction) switchViews:(id) sender {
	[UIView beginAnimations:@"View Flip" context:nil];
	[UIView setAnimationDuration:1.25];
	[UIView	setAnimationCurve:UIViewAnimationCurveEaseInOut];
	
	if (self.ivController.view.superview == nil) {
		if (self.ivController == nil) {
			InfoViewController *ivc = [[InfoViewController alloc] initWithNibName:@"InfoView"
																							bundle:nil]; 
			self.ivController = ivc;
			[ivc release];
		} 
		[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
		[pvController viewWillAppear:YES];
		[ivController viewWillDisappear:YES];
		[pvController.view removeFromSuperview]; 
		[self.view insertSubview:ivController.view atIndex:0]; 
		[ivController viewDidDisappear:YES]; 
		[pvController viewDidAppear:YES];
		
	}else {
		if (self.pvController == nil) {
			PerumalViewController *pvc = [[PerumalViewController alloc] initWithNibName:@"PermulaView"
																					  bundle:nil]; 
			self.pvController = pvc;
			[pvc release];
		} 
		[UIView setAnimationTransition:
		 UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
		[ivController viewWillAppear:YES]; 
		[pvController viewWillDisappear:YES];
		[ivController.view removeFromSuperview]; 
		[self.view insertSubview:pvController.view atIndex:0];
		[pvController viewDidDisappear:YES]; 
		[ivController viewDidAppear:YES];
	} 
	
	[UIView commitAnimations];
	
}

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.*/
- (void)viewDidLoad {
	PerumalViewController * pvc = [[PerumalViewController alloc] initWithNibName:@"PerumalView" bundle:nil];
	self.pvController = pvc;
	[self.view insertSubview:pvc.view atIndex:0];
	[pvc release];
	
    [super viewDidLoad];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
